<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Data Structures for Sets and Graphs: datastruct/Hash.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Data Structures for Sets and Graphs
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Macros</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_f9af7c4329e6f916a6a58dc83cbb7ef1.html">datastruct</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Hash.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="Hash_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#ifndef HASH_H_</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor"></span><span class="preprocessor">#define HASH_H_</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor"></span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &lt;cstdlib&gt;</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="preprocessor">#include &lt;cmph.h&gt;</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#include &lt;assert.h&gt;</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00026"></a><span class="lineno"><a class="code" href="Hash_8h.html#ac38933629c27b65fa1855f2303bdc6d0">   26</a></span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="Hash_8h.html#ac38933629c27b65fa1855f2303bdc6d0">hashcompar</a>(<span class="keyword">const</span> <span class="keywordtype">void</span> *a, <span class="keyword">const</span> <span class="keywordtype">void</span> *b) {</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;        <span class="keywordflow">return</span> *((T *) a) &lt; *((T *) b) ? -1 : *((T *) a) == *((T *) b) ? 0 : 1;</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;}</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;</div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00040"></a><span class="lineno"><a class="code" href="classHash.html">   40</a></span>&#160;<span class="keyword">class </span><a class="code" href="classHash.html" title="An interface to packed perfect hashing with cmph.">Hash</a> {</div>
<div class="line"><a name="l00041"></a><span class="lineno"><a class="code" href="classHash.html#aea88561fddd2e924cebf793f0cfdc8b6">   41</a></span>&#160;        <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classHash.html#aea88561fddd2e924cebf793f0cfdc8b6">Search</a>;</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;</div>
<div class="line"><a name="l00043"></a><span class="lineno"><a class="code" href="classHash.html#afe49a7ea85fe8259dc751c451ebc0906">   43</a></span>&#160;        <span class="keywordtype">size_t</span>          <a class="code" href="classHash.html#afe49a7ea85fe8259dc751c451ebc0906" title="in the struct T">key_offset</a>;     </div>
<div class="line"><a name="l00044"></a><span class="lineno"><a class="code" href="classHash.html#a035d8296ce745c37829cb286e7c905c6">   44</a></span>&#160;        <span class="keywordtype">size_t</span>          <a class="code" href="classHash.html#a035d8296ce745c37829cb286e7c905c6" title="in bytes">key_len</a>;        </div>
<div class="line"><a name="l00045"></a><span class="lineno"><a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381">   45</a></span>&#160;        <span class="keywordtype">void</span> *          <a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a>;        </div>
<div class="line"><a name="l00046"></a><span class="lineno"><a class="code" href="classHash.html#a5225bd53a5a66ccd0255d4d1366be69e">   46</a></span>&#160;        <span class="keywordtype">size_t</span>          <a class="code" href="classHash.html#a5225bd53a5a66ccd0255d4d1366be69e" title="number of elements in the table">nelem</a>;          </div>
<div class="line"><a name="l00047"></a><span class="lineno"><a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e">   47</a></span>&#160;        <span class="keywordtype">size_t</span>          <a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a>;</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div>
<div class="line"><a name="l00053"></a><span class="lineno"><a class="code" href="classHash_1_1Search.html">   53</a></span>&#160;        <span class="keyword">class </span><a class="code" href="classHash_1_1Search.html" title="An interface to the search object.">Search</a> {</div>
<div class="line"><a name="l00054"></a><span class="lineno"><a class="code" href="classHash_1_1Search.html#ae6b92b2e0be47b032ba4d225e8b01663">   54</a></span>&#160;                <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classHash.html" title="An interface to packed perfect hashing with cmph.">Hash</a>;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;                <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> <a class="code" href="classHash_1_1Search.html#a5343064197044acd72e269c239a7ed8c" title="Computes the index of the specified element in the specified perfect hash table.">search</a>(<span class="keywordtype">void</span> * table, <span class="keyword">const</span> T * key, cmph_uint32 keylen) = 0;</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;        <span class="keyword">protected</span>:</div>
<div class="line"><a name="l00068"></a><span class="lineno"><a class="code" href="classHash_1_1Search.html#a15ad59b6458d7f430921b18cb7809ca9">   68</a></span>&#160;                <span class="keyword">virtual</span> <a class="code" href="classHash_1_1Search.html#a15ad59b6458d7f430921b18cb7809ca9">~Search</a>() {};</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        };</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;</div>
<div class="line"><a name="l00075"></a><span class="lineno"><a class="code" href="classHash_1_1CMPHSearch.html">   75</a></span>&#160;        <span class="keyword">class </span><a class="code" href="classHash_1_1CMPHSearch.html" title="An implementation of Search the cmph package.">CMPHSearch</a> : <span class="keyword">public</span> <a class="code" href="classHash_1_1Search.html" title="An interface to the search object.">Search</a> {</div>
<div class="line"><a name="l00076"></a><span class="lineno"><a class="code" href="classHash_1_1CMPHSearch.html#ae6b92b2e0be47b032ba4d225e8b01663">   76</a></span>&#160;                <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classHash.html" title="An interface to packed perfect hashing with cmph.">Hash</a>;</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;                <span class="keywordtype">size_t</span> <a class="code" href="classHash_1_1CMPHSearch.html#a38f6346853bcc32d2e5a69ca8fd32eb2" title="Computes the index of the specified element in the specified perfect hash table.">search</a>(<span class="keywordtype">void</span> * table, <span class="keyword">const</span> T * key, cmph_uint32 keylen);</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        };</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div>
<div class="line"><a name="l00085"></a><span class="lineno"><a class="code" href="classHash_1_1BinSearch.html">   85</a></span>&#160;        <span class="keyword">class </span><a class="code" href="classHash_1_1BinSearch.html" title="An implementation of Search using binary search in an ordered table.">BinSearch</a> : <span class="keyword">public</span> <a class="code" href="classHash_1_1Search.html" title="An interface to the search object.">Search</a> {</div>
<div class="line"><a name="l00086"></a><span class="lineno"><a class="code" href="classHash_1_1BinSearch.html#ae6b92b2e0be47b032ba4d225e8b01663">   86</a></span>&#160;                <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="classHash.html" title="An interface to packed perfect hashing with cmph.">Hash</a>;</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;</div>
<div class="line"><a name="l00088"></a><span class="lineno"><a class="code" href="classHash_1_1BinSearch.html#ade4af73137c151d1d74b2ebdb43c12aa">   88</a></span>&#160;                <a class="code" href="classHash.html" title="An interface to packed perfect hashing with cmph.">Hash</a> *  <a class="code" href="classHash_1_1BinSearch.html#ade4af73137c151d1d74b2ebdb43c12aa" title="the associated Hash object">h</a>;      </div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;</div>
<div class="line"><a name="l00095"></a><span class="lineno"><a class="code" href="classHash_1_1BinSearch.html#a0b480eb960b36d7b2c7906b884900153">   95</a></span>&#160;                <a class="code" href="classHash_1_1BinSearch.html#a0b480eb960b36d7b2c7906b884900153" title="Creates a new object for the associated Hash object.">BinSearch</a>(<a class="code" href="classHash.html" title="An interface to packed perfect hashing with cmph.">Hash</a> * <a class="code" href="classHash_1_1BinSearch.html#ade4af73137c151d1d74b2ebdb43c12aa" title="the associated Hash object">h</a>) : h(h) {};</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;                <span class="keywordtype">size_t</span> <a class="code" href="classHash_1_1BinSearch.html#aac217c00102fdd08a30ec0879bb0fe05" title="Computes the index of the specified element in the specified perfect hash table.">search</a>(<span class="keywordtype">void</span> * table, <span class="keyword">const</span> T * key, cmph_uint32 keylen);</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;        };</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;</div>
<div class="line"><a name="l00099"></a><span class="lineno"><a class="code" href="classHash.html#a041ae966f44c256333f68fef549a053b">   99</a></span>&#160;        int (*<a class="code" href="classHash.html#a041ae966f44c256333f68fef549a053b" title="it is expected to have two arguments which point to a key object and to an array member&#39;s key...">compar</a>)(<span class="keyword">const</span> <span class="keywordtype">void</span> *, <span class="keyword">const</span> <span class="keywordtype">void</span> *);      </div>
<div class="line"><a name="l00100"></a><span class="lineno"><a class="code" href="classHash.html#aa72bab5659a7bfedf7a7e33074b89103">  100</a></span>&#160;        <a class="code" href="classHash.html#aea88561fddd2e924cebf793f0cfdc8b6">Search</a> *                <a class="code" href="classHash.html#aa72bab5659a7bfedf7a7e33074b89103" title="current object Search object">s</a>;              </div>
<div class="line"><a name="l00101"></a><span class="lineno"><a class="code" href="classHash.html#ae90bc6965f9447ad87736c77d6f43410">  101</a></span>&#160;        CMPHSearch *    <a class="code" href="classHash.html#ae90bc6965f9447ad87736c77d6f43410" title="Search object to search in the cmph table.">cmphs</a>;  </div>
<div class="line"><a name="l00102"></a><span class="lineno"><a class="code" href="classHash.html#ab9622513f2e957b9db790c4032ccbfb4">  102</a></span>&#160;        BinSearch *     <a class="code" href="classHash.html#ab9622513f2e957b9db790c4032ccbfb4" title="Search object to search in an ordered table.">bins</a>;   </div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;        <a class="code" href="classHash.html#a2e7e282b9f830b27004d3a3f596a0e64" title="Creates an empty parfect hash table.">Hash</a>(<span class="keywordtype">size_t</span> <a class="code" href="classHash.html#afe49a7ea85fe8259dc751c451ebc0906" title="in the struct T">key_offset</a>, <span class="keywordtype">size_t</span> <a class="code" href="classHash.html#a035d8296ce745c37829cb286e7c905c6" title="in bytes">key_len</a>, <span class="keywordtype">int</span> (*<a class="code" href="classHash.html#a041ae966f44c256333f68fef549a053b" title="it is expected to have two arguments which point to a key object and to an array member&#39;s key...">compar</a>)(<span class="keyword">const</span> <span class="keywordtype">void</span> *, <span class="keyword">const</span> <span class="keywordtype">void</span> *));</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;        <a class="code" href="classHash.html#a3690930041a748071efe477824491650">~Hash</a>();</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;        <span class="keywordtype">void</span> <a class="code" href="classHash.html#a1ef2beb4c2383079120b33866f535091" title="Renews this perfect hash table with the specified keys.">renew</a>(T * key, <span class="keywordtype">size_t</span> nk);</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;        <span class="keywordtype">size_t</span> <a class="code" href="classHash.html#a72564107e3d223d1388c64c86e8d6072" title="Computes the index of the specified element in this perfect hash table.">search</a>(<span class="keyword">const</span> T *key);</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;        <span class="keywordtype">size_t</span> <a class="code" href="classHash.html#a44dfebdb7d2c909bf3e7e7f4ee65554e" title="Gets the number of elements currently in this parfect hash table.">size</a>();</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;};</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00141"></a><span class="lineno"><a class="code" href="classHash.html#a2e7e282b9f830b27004d3a3f596a0e64">  141</a></span>&#160;<span class="keyword">inline</span> <a class="code" href="classHash.html#a2e7e282b9f830b27004d3a3f596a0e64" title="Creates an empty parfect hash table.">Hash&lt;T&gt;::Hash</a>(<span class="keywordtype">size_t</span> key_offset, <span class="keywordtype">size_t</span> key_len, <span class="keywordtype">int</span> (*<a class="code" href="classHash.html#a041ae966f44c256333f68fef549a053b" title="it is expected to have two arguments which point to a key object and to an array member&#39;s key...">compar</a>)(<span class="keyword">const</span> <span class="keywordtype">void</span> *, <span class="keyword">const</span> <span class="keywordtype">void</span> *)) : key_offset(key_offset), key_len(key_len), <a class="code" href="classHash.html#a5225bd53a5a66ccd0255d4d1366be69e" title="number of elements in the table">nelem</a>(0), <a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a>(0), <a class="code" href="classHash.html#a041ae966f44c256333f68fef549a053b" title="it is expected to have two arguments which point to a key object and to an array member&#39;s key...">compar</a>(<a class="code" href="classHash.html#a041ae966f44c256333f68fef549a053b" title="it is expected to have two arguments which point to a key object and to an array member&#39;s key...">compar</a>) {</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;        <a class="code" href="classHash.html#ae90bc6965f9447ad87736c77d6f43410" title="Search object to search in the cmph table.">cmphs</a> = <span class="keyword">new</span> <a class="code" href="classHash_1_1CMPHSearch.html" title="An implementation of Search the cmph package.">Hash&lt;T&gt;::CMPHSearch</a>();</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;        <a class="code" href="classHash.html#ab9622513f2e957b9db790c4032ccbfb4" title="Search object to search in an ordered table.">bins</a> = <span class="keyword">new</span> <a class="code" href="classHash_1_1BinSearch.html" title="An implementation of Search using binary search in an ordered table.">Hash&lt;T&gt;::BinSearch</a>(<span class="keyword">this</span>);</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;}</div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;</div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00147"></a><span class="lineno"><a class="code" href="classHash.html#a3690930041a748071efe477824491650">  147</a></span>&#160;<span class="keyword">inline</span> <a class="code" href="classHash.html#a3690930041a748071efe477824491650">Hash&lt;T&gt;::~Hash</a>() {</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a> &gt; 0) free(<a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a>);</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;        <span class="keyword">delete</span> <a class="code" href="classHash.html#ae90bc6965f9447ad87736c77d6f43410" title="Search object to search in the cmph table.">cmphs</a>;</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;        <span class="keyword">delete</span> <a class="code" href="classHash.html#ab9622513f2e957b9db790c4032ccbfb4" title="Search object to search in an ordered table.">bins</a>;</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;};</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00154"></a><span class="lineno"><a class="code" href="classHash.html#a1ef2beb4c2383079120b33866f535091">  154</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classHash.html#a1ef2beb4c2383079120b33866f535091" title="Renews this perfect hash table with the specified keys.">Hash&lt;T&gt;::renew</a>(T * key, <span class="keywordtype">size_t</span> nk) {</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;        <span class="keywordflow">if</span> (nk &gt; 7) {</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;                cmph_io_adapter_t * hash_adapter = cmph_io_struct_vector_adapter(key, <span class="keyword">sizeof</span>(T), key_offset, key_len, nk);</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;                cmph_config_t * hash_config = cmph_config_new(hash_adapter);</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;                cmph_config_set_algo(hash_config, CMPH_CHD);</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;                <span class="comment">//              cmph_config_set_verbosity(hash_config,1);</span></div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;                cmph_t * h = cmph_new(hash_config);</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;                <a class="code" href="classHash.html#a5225bd53a5a66ccd0255d4d1366be69e" title="number of elements in the table">nelem</a> = nk;</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;                <a class="code" href="classHash.html#aa72bab5659a7bfedf7a7e33074b89103" title="current object Search object">s</a> = <a class="code" href="classHash.html#ae90bc6965f9447ad87736c77d6f43410" title="Search object to search in the cmph table.">cmphs</a>;</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;                <span class="keywordtype">int</span> phsz = cmph_packed_size(h);</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;                <span class="keywordflow">if</span> (phsz &gt; <a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a> || (phsz &lt;&lt; 1) &lt; <a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a>) {</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;                        <span class="keywordflow">if</span> (<a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a> &gt; 0)</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;                                free(<a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a>);</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;                        <a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a> = malloc(phsz);</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;                        <a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a> = phsz;</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;                }</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;                cmph_pack(h, <a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a>);</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;                cmph_io_struct_vector_adapter_destroy(hash_adapter);</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;                cmph_config_destroy(hash_config);</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;                cmph_destroy(h);</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;        }</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;        <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;                <a class="code" href="classHash.html#a5225bd53a5a66ccd0255d4d1366be69e" title="number of elements in the table">nelem</a> = nk;</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;                <a class="code" href="classHash.html#aa72bab5659a7bfedf7a7e33074b89103" title="current object Search object">s</a> = <a class="code" href="classHash.html#ab9622513f2e957b9db790c4032ccbfb4" title="Search object to search in an ordered table.">bins</a>;</div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;                <span class="keywordtype">int</span> phsz = <a class="code" href="classHash.html#a5225bd53a5a66ccd0255d4d1366be69e" title="number of elements in the table">nelem</a> * <a class="code" href="classHash.html#a035d8296ce745c37829cb286e7c905c6" title="in bytes">key_len</a>;</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;                <span class="keywordflow">if</span> (phsz &gt; <a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a> || (phsz &lt;&lt; 1) &lt; <a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a>) {</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;                        <span class="keywordflow">if</span> (<a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a> &gt; 0)</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;                                free(<a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a>);</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;                        <span class="keywordflow">if</span> (phsz &gt; 0)</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;                                <a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a> = malloc(phsz);</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;                        <a class="code" href="classHash.html#a84b77b59bd8e66fc9502bfdacf4afa4e" title="size of the packed table">packed_size</a> = phsz;</div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;                }</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;                memcpy(<a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a>, key, phsz);</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;                qsort(<a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a>, <a class="code" href="classHash.html#a5225bd53a5a66ccd0255d4d1366be69e" title="number of elements in the table">nelem</a>, key_len, <a class="code" href="classHash.html#a041ae966f44c256333f68fef549a053b" title="it is expected to have two arguments which point to a key object and to an array member&#39;s key...">compar</a>);</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;        }</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;}</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00195"></a><span class="lineno"><a class="code" href="classHash.html#a72564107e3d223d1388c64c86e8d6072">  195</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">size_t</span> <a class="code" href="classHash.html#a72564107e3d223d1388c64c86e8d6072" title="Computes the index of the specified element in this perfect hash table.">Hash&lt;T&gt;::search</a>(<span class="keyword">const</span> T * key) {</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="classHash.html#aa72bab5659a7bfedf7a7e33074b89103" title="current object Search object">s</a>-&gt;<a class="code" href="classHash_1_1Search.html#a5343064197044acd72e269c239a7ed8c" title="Computes the index of the specified element in the specified perfect hash table.">search</a>(<a class="code" href="classHash.html#a1f38ab7c36ba7e5c1a00c27185cdc381" title="packed table">hashtab</a>, key, key_len);</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;}</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00200"></a><span class="lineno"><a class="code" href="classHash.html#a44dfebdb7d2c909bf3e7e7f4ee65554e">  200</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">size_t</span> <a class="code" href="classHash.html#a44dfebdb7d2c909bf3e7e7f4ee65554e" title="Gets the number of elements currently in this parfect hash table.">Hash&lt;T&gt;::size</a>() {</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="classHash.html#a5225bd53a5a66ccd0255d4d1366be69e" title="number of elements in the table">nelem</a>;</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;}</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;</div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00205"></a><span class="lineno"><a class="code" href="classHash_1_1CMPHSearch.html#a38f6346853bcc32d2e5a69ca8fd32eb2">  205</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">size_t</span> <a class="code" href="classHash_1_1CMPHSearch.html#a38f6346853bcc32d2e5a69ca8fd32eb2" title="Computes the index of the specified element in the specified perfect hash table.">Hash&lt;T&gt;::CMPHSearch::search</a>(<span class="keywordtype">void</span> * table, <span class="keyword">const</span> T * key, cmph_uint32 keylen) {</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;        <span class="keywordflow">return</span> cmph_search_packed(table, (<span class="keywordtype">char</span> *) key, keylen);</div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;};</div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;</div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00210"></a><span class="lineno"><a class="code" href="classHash_1_1BinSearch.html#aac217c00102fdd08a30ec0879bb0fe05">  210</a></span>&#160;<span class="keyword">inline</span> <span class="keywordtype">size_t</span> <a class="code" href="classHash.html#a72564107e3d223d1388c64c86e8d6072" title="Computes the index of the specified element in this perfect hash table.">Hash&lt;T&gt;::BinSearch::search</a>(<span class="keywordtype">void</span> * table, <span class="keyword">const</span> T * key, cmph_uint32 keylen) {</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;        <span class="keywordflow">return</span> ((<span class="keywordtype">char</span> *) bsearch(key, table, h-&gt;nelem, keylen, h-&gt;compar) - (<span class="keywordtype">char</span> *) table)/keylen;</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;};</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;<span class="preprocessor">#endif </span><span class="comment">/* HASH_H_ */</span><span class="preprocessor"></span></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Mon Nov 26 2012 17:06:45 for Data Structures for Sets and Graphs by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.1
</small></address>
</body>
</html>
